import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hockey/extensions/jzx_widget_extension.dart';
import 'package:hockey/jzx_apps.dart';
import 'package:hockey/network/jzx_apis.dart';
import 'package:hockey/utils/Jzx_launch.dart';

import 'controller.dart';

class JzxLoginView extends GetView<JzxLoginController> {
  const JzxLoginView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: [
        Positioned(
          left: 48.w,
          right: 48.w,
          top: 220.w + kNavigationBarHeight,
          child: Column(
            children: [
              Assets.logo.appLogo.image(
                width: 108.r,
                height: 108.r,
              ),
              JzxGaps.h100,
              _AppleButton(onTap: controller.appleLoginAct),
              JzxGaps.h32,
              _QuickButton(onTap: controller.quickLoginAct),
              JzxGaps.h48,
              const _PrivacyView(),
            ],
          ),
        ),
      ].backgroud([
        // Assets.images.launchBgv,
        Assets.images.normalBgv,
      ]),
    );
  }
}

class _AppleButton extends StatelessWidget {
  const _AppleButton({
    this.onTap,
  });

  final VoidCallback? onTap;

  @override
  Widget build(BuildContext context) {
    return PrimaryButton(
      padding: EdgeInsets.symmetric(horizontal: 40.w),
      onPressed: onTap,
      gradient: LinearGradient(colors: [
        '#FF3FE1D8'.hexColor,
        '#FF63FF6A'.hexColor,
      ]),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Assets.images.icAppleLogin.image(width: 24.w),
          Expanded(
            child: Text(
              'Sign in with Apple',
              textAlign: TextAlign.center,
              style: GoogleFonts.anekDevanagari(
                fontSize: 16.w,
                color: Colors.white,
              ),
            ).paddingOnly(top: 4.w),
          )
        ],
      ),
    );
  }
}

class _QuickButton extends StatelessWidget {
  const _QuickButton({
    this.onTap,
  });

  final VoidCallback? onTap;

  @override
  Widget build(BuildContext context) {
    return PrimaryButton(
      onPressed: onTap,
      padding: EdgeInsets.symmetric(horizontal: 40.w),
      backgroundColor: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Assets.images.icQuickLogin.image(width: 24.w),
          Expanded(
            child: Text(
              'Fast Login',
              textAlign: TextAlign.center,
              style: GoogleFonts.anekDevanagari(
                fontSize: 16.w,
                color: '#FF333333'.hexColor,
              ),
            ).paddingOnly(top: 4.w),
          )
        ],
      ),
    );
  }
}

class _PrivacyView extends GetView<JzxLoginController> {
  const _PrivacyView();

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Obx(
          () => InkWell(
            onTap: () {
              controller.isAgree.toggle();
            },
            child: (controller.isAgree.value
                    ? Assets.images.icSelected
                    : Assets.images.icUnselected)
                .image(width: 16.w, height: 16.w),
          ),
        ),
        JzxGaps.w8,
        Expanded(
          child: Text.rich(
            TextSpan(children: [
              const TextSpan(text: 'By using our App you agree with our '),
              TextSpan(
                text: 'Term of Use',
                style: GoogleFonts.anekDevanagari(
                  color: '#FF4DEDAF'.hexColor,
                  decoration: TextDecoration.underline,
                ),
                recognizer: TapGestureRecognizer()
                  ..onTap = () {
                    JzxLaunch.openUrl(kH5TermConditions);
                    JzxLogPvManger.tracking(page: JzxLogPages.terms);
                  },
              ),
              const TextSpan(text: ' and '),
              TextSpan(
                text: 'Privacy Policy.',
                style: GoogleFonts.anekDevanagari(
                  decoration: TextDecoration.underline,
                  color: '#FF4DEDAF'.hexColor,
                ),
                recognizer: TapGestureRecognizer()
                  ..onTap = () {
                    JzxLaunch.openUrl(kH5PrivacyPolicy);
                    JzxLogPvManger.tracking(page: JzxLogPages.privacy);
                  },
              ),
            ]),
            style: GoogleFonts.anekDevanagari(
                fontSize: 12.sp,
                color: Colors.white,
                fontWeight: FontWeight.bold),
          ),
        ),
      ],
    ).paddingSymmetric(horizontal: 10.w);
  }
}
